package com.op.teachingliteapp.database.table;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.op.teachingliteapp.BuildConfig;

/**
 * 用户表
 * 
 * @author Michael
 * @date Jun 23, 2015
 */
public class UserTable implements BaseColumn {

	private static final String TAG = UserTable.class.getSimpleName();

	// User table
	public static final String TABLE_USER = "user";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_NUMBER = "number";
	public static final String COLUMN_PHONE = "phone";
	public static final String COLUMN_EMAIL = "email";
	public static final String COLUMN_PASSWORD = "password";
	public static final String COLUMN_IS_USING = "isUsing";
	public static final String COLUMN_TYPE = "type";
	public static final String COLUMN_IMAGE_URL = "imageUrl";

	public static final String[] PROJECTION = { COLUMN_ID, COLUMN_NAME, COLUMN_NUMBER, COLUMN_PHONE, COLUMN_EMAIL, COLUMN_CREATE_TIME, COLUMN_UPDATE_TIME, COLUMN_PASSWORD, COLUMN_IMAGE_URL, COLUMN_IS_USING, COLUMN_TYPE };

	// Table creation SQL statement
	private static final String CREATE_TABLE = "create table " + TABLE_USER + "(" + COLUMN_ID + " text primary key, " + COLUMN_NAME + " text, " + COLUMN_NUMBER + " text, " + COLUMN_PHONE + " text, " + COLUMN_EMAIL + " text, " + COLUMN_CREATE_TIME + " text, " + COLUMN_UPDATE_TIME + " text, "
			+ COLUMN_PASSWORD + " text, " + COLUMN_IS_USING + " text, " + COLUMN_TYPE + " text, " + COLUMN_IMAGE_URL + " text" + ");";

	public static void onCreate(SQLiteDatabase db) {
		if (BuildConfig.DEBUG) {
			Log.i(TAG, "Creating user table");
		}
		db.execSQL(CREATE_TABLE);
	}

	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (BuildConfig.DEBUG) {
			Log.i(TAG, "Upgrading user table");
		}
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
		onCreate(db);
	}
}
